package com.example.yk_fx.video;

import android.util.AndroidException;

import androidx.lifecycle.MutableLiveData;

import com.example.yk_fx.base.BaseRepo;
import com.example.yk_fx.entity.PlEntity;
import com.example.yk_fx.entity.ResultEntity;
import com.example.yk_fx.entity.VideoEntity;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import master.flame.danmaku.danmaku.parser.android.AndroidFileSource;
import okhttp3.RequestBody;

public class VideoRepo extends BaseRepo {

    public void video(int page, int size, MutableLiveData<VideoEntity> success,MutableLiveData<String> fail){
        api.video(page,size)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<VideoEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(VideoEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void love(int id, MutableLiveData<ResultEntity> success,MutableLiveData<String> fail){
        api.love(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void nolove(int id,MutableLiveData<ResultEntity> success,MutableLiveData<String> fail){
        api.nolove(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ResultEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(ResultEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void getPl(int videoId, MutableLiveData<PlEntity> success,MutableLiveData<String> fail){
        api.getPl(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PlEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PlEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    public void sendPl(RequestBody body,MutableLiveData<PlEntity> success,MutableLiveData<String> fail){
        api.sendPl(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PlEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PlEntity entity) {
                        success.postValue(entity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        fail.postValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }
}
